package sky.tro.finders;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 06.10.13
 * Time: 17:39
 * To change this template use File | Settings | File Templates.
 */
public class CityFinder implements Serializable, AbstractFinder {

    private String countryName = "";

    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    public boolean isEmpty() {
        return countryName==null;
    }

    @Override
    public Criteria fillCriteria(Criteria criteria) {
        if (getCountryName()!=null) {
            criteria.createAlias("country", "country")
                    .add(Restrictions.eq("country.name", getCountryName()));
        }
        return criteria;
    }
}
